def tuple_map(fn, t, **kwargs):
    if t is None:
        return None
    if type(t) not in {list, tuple}:
        return fn(t, **kwargs)
    return tuple(tuple_map(fn, s, **kwargs) for s in t)
